package app.common.utils.wdt.sdk.taobao;

import com.qimencloud.api.DefaultQimenCloudClient;
import com.qimencloud.api.QimenCloudClient;
import com.qimencloud.api.scene3ldsmu02o9.request.WdtWmsStockinOtherCreateotherstockinorderRequest;
import com.qimencloud.api.scene3ldsmu02o9.request.WdtWmsStockspecQuerychangehistoryRequest;
import com.qimencloud.api.scene3ldsmu02o9.response.WdtWmsStockinOtherCreateotherstockinorderResponse;
import com.qimencloud.api.scene3ldsmu02o9.response.WdtWmsStockspecQuerychangehistoryResponse;
import com.taobao.api.ApiException;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

public class WdtCustomizeTest1 {

	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//	static String serverUrl = "http://3ldsmu02o9.api.taobao.com/top/router/qmtest";
	static String serverUrl = "http://3ldsmu02o9.api.taobao.com/top/router/qm";

	/*
	static String appKey = "appkey";// 自己的appkey
	static String appSecret = "appsecret";// 自己的appsecret
	static String targetAppKey = "21363512";// WDT的appkey
	static String wdtAppKey = "wdt_appkey";
	static String wdtAppSecret = "secret:salt";
	static String wdtSalt = wdtAppSecret.split(":")[1];
	static String wdtSecret = wdtAppSecret.split(":")[0];
	 */
	static String appKey = "34331853";// 自己的appkey
	static String appSecret = "f169f72d0be4fd0ef4412dbd494fafaa";// 自己的appsecret
//	static String appSecret = "xxx";// 自己的appsecret
	static String targetAppKey = "21363512";// WDT的appkey
	static String wdtAppKey = "34331853";
//	static String wdtAppKey = "wdt_appkey";
	static String wdtAppSecret = "af5ed5b3dbd456357748fb995510fff5:45629849787249829634d47028365251";
//	static String wdtAppSecret = "secret:salt";
	static String wdtSalt = wdtAppSecret.split(":")[1];
	static String wdtSecret = wdtAppSecret.split(":")[0];


	public static void main(String[] args) throws ApiException
	{
		testQueryStockSpecChangeHistory();
//		testCreateOtherOut();
	}

	static void testQueryStockSpecChangeHistory() throws ApiException
	{
		QimenCloudClient client = new DefaultQimenCloudClient(serverUrl, appKey, appSecret);
//		client.execute()
		WdtWmsStockspecQuerychangehistoryRequest request = new WdtWmsStockspecQuerychangehistoryRequest();
		request.setTargetAppKey(targetAppKey);

		String dateTime = sdf.format(new Date());
		request.setDatetime(dateTime);
		request.putOtherTextParam("wdt3_customer_id", "weikang3");
		WdtWmsStockspecQuerychangehistoryRequest.Params params = new WdtWmsStockspecQuerychangehistoryRequest.Params();
		params.setSpecNo(null);
		params.setStartDate("2020-08-23 00:00:00");
		params.setEndDate("2020-09-20 00:00:00");
		params.setWarehouseNo("1001");
		request.setParams(params);

		WdtWmsStockspecQuerychangehistoryRequest.Pager pager = new WdtWmsStockspecQuerychangehistoryRequest.Pager();
		pager.setPageNo(1L);
		pager.setPageSize(10L);
		request.setPager(pager);

		request.setWdtAppkey(wdtAppKey);
		request.setWdtSalt(wdtSalt);
		request.setWdtSign(Utils.getQimenCustomWdtSign(request, wdtSecret));

		WdtWmsStockspecQuerychangehistoryResponse response = client.execute(request);
		System.out.println(response.getBody());
	}

	static void testCreateOtherOut() throws ApiException
	{
		WdtWmsStockinOtherCreateotherstockinorderRequest request = new WdtWmsStockinOtherCreateotherstockinorderRequest();

		WdtWmsStockinOtherCreateotherstockinorderRequest.StockinOrder order = new WdtWmsStockinOtherCreateotherstockinorderRequest.StockinOrder();
		order.setOuterNo("outer_no");
		order.setWarehouseNo("warehouse_no");

		request.setStockinOrder(order);
		WdtWmsStockinOtherCreateotherstockinorderRequest.GoodsList goods = new WdtWmsStockinOtherCreateotherstockinorderRequest.GoodsList();
		goods.setNum("2");
		goods.setSpecNo("daba1");
		order.setGoodsList(Arrays.asList(goods));

		request.setTargetAppKey("21363512");

		String dateTime = sdf.format(new Date());
		request.setDatetime(dateTime);
//		request.putOtherTextParam("wdt3_customer_id", "wdtapi3");
		request.setWdtAppkey(wdtAppKey);
		request.setWdtSalt(wdtSalt);
		request.setWdtSign(Utils.getQimenCustomWdtSign(request, wdtSecret));

		QimenCloudClient client = new DefaultQimenCloudClient(serverUrl, appKey, appSecret);
		WdtWmsStockinOtherCreateotherstockinorderResponse response = client.execute(request);
		System.out.println(response.getBody());

//		request.setw
	}
}
